package models;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import play.data.validation.Email;
import play.data.validation.Password;
import play.data.validation.Required;
import play.db.jpa.Model;

@Entity
public class User extends Model {
	
    public String access_token;
	
	@Required
	public String firstName;
	
	@Required
	public String lastName;
	
	@Required
	@Email
	public String email;
	
	@Password
	public String password;
	
	@OneToOne
	public ShoppingCart currentShoppingCart;
	
	@OneToMany
	public List<PurchasedOrder> purchasedOrders; 

	@OneToOne
	public ShippingInformation shippingInformation;
	
	@OneToOne
	public DietInformation dietInformation;
	
	public User(String firstName, String lastName, String email) {
		this(firstName, lastName, email, null);
	}
	
	public User(String firstName, String lastName, String email, String password) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.password = password;
	}

	public boolean checkPassword(String encryptedPassword) {
		
		if(this.password.equals(encryptedPassword))
			return true;
		return false;
	}
}
